<?php
    require "config.php";
	
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $name=$_POST['name'];
    $pass=$_POST['password'];
    $email=$_POST['email'];
    $gender=$_POST['sex'];
    $phone=$_POST['phone'];

    $con = mysql_connect($db_host,$db_user,$db_pass);

    if (!$con)
	{
		die('Could not connect: ' . mysql_error());
               }
    mysql_select_db($db_name, $con);

if(preg_match('/^(NA|[0-9+-]+)$/',$phone) && (preg_match("/^[^0-9][_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/",
               $email)))
   {
    $sql_add = "INSERT INTO register (fname, lname, uname, pass, email, gender, phone) VALUES ('$fname', '$lname', '$name', '$pass', '$email', '$gender', '$phone');";
	$result1 = mysql_query($sql_add);
	
		if(!$result1)
		{
		print '<script type="text/javascript">'; 
		print 'alert("User already exist")'; 
		print '</script>';
		require "registration.php";
		}
		else 
		{//echo "you have been registered successfully\n";
		 //echo '<h2>Login!</h2>';
	session_start();
	$_SESSION['username']=$name; 
	 $_SESSION['firstname']= $fname;
	 $_SESSION['lastname']= $lname;
			require"search.php";}
	}
	    
else 
      {  print '<script type="text/javascript">'; 
		print 'alert("invalid number or email")'; 
		print '</script>';
		require "registration.php";
             }    
    
    mysql_close($con); 
    

?>
